package com.nulldev.util.web.YouTubeExtractor.formats;

import java.util.Map;

import com.nulldev.util.data.Arrays.maps.FastMaps;

class FormatUtils {

	private static final float WIDTH_RATIO = 1.777777777f; /* 16:9 */
	private static final Map<Integer, Integer> /* [height, width] */ map = FastMaps.fixedUniMap(new Object[][]
		{
				{ 4320, 7680 },
				{ 2160, 3840 },
				{ 1440, 2560 },
				{ 1080, 1920 },
				{ 720, 1280 },
				{ 480, 854 },
				{ 360, 640 },
				{ 240, 426 },
				{ 144, 256 } });

	public static int guessFromHeight(final int height) {
		final int width = map.getOrDefault(height, -1);
		if (width == -1) {
			return (int) Math.ceil(height * WIDTH_RATIO);
		} else {
			return width;
		}
	}

}
